package main

import (
	"fmt"
	"sync"
)

func doWorker(id int,
	w worker)  {
	for n := range w.in{
		fmt.Printf("worker %d ,receive  %c \n", id, n)
		w.done()
	}

}

type worker struct {
	in chan int
	//done chan bool
	done func()
}
func createWorker(id int,wg *sync.WaitGroup) worker {
	w := worker{
		in : make(chan int),
		done : func() {
			wg.Done()
		},
	}
	go doWorker(id,w)
	return w
}
func chanDemo() {
	//var channels [10] chan <-int
	var workers [26] worker
	var wg sync.WaitGroup
	wg.Add(len(workers)*2)

	for i := 0; i < len(workers); i++ {
		workers[i] = createWorker(i,&wg)
	}

	for i,worker  := range workers {
		worker.in <- 'a' + i
	}

	for i,worker  := range workers {
		worker.in <- 'A' + i
	}
	wg.Wait()

	//time.Sleep(time.Microsecond)
}

func main() {
	chanDemo()

}
